<template>
	<view>
		<cu-custom bgColor="bg-blue2" :isBack="false" ><block slot="backText"></block><block slot="content">首页</block></cu-custom>
		<view class="bg-blue2 solids-bottom padding-xs flex align-center" >
			<view class="flex-sub text-center">
				<view class="text-xxl">
					<text class="padding">{{goodsInBillYesterday}}</text>
				</view>
				<view class="padding">昨日入库量</view>
			</view>
			<view class="flex-sub text-center">
				<view class="text-xxl">
					<text class="padding">{{goodsOutBillYesterday}}</text>
				</view>
				<view class="padding">昨日出库量</view>
			</view>
			<view class="flex-sub text-center">
				<view class="text-xxl">
					<text class="padding">{{inStockGoodsDetailOnDayList}}</text>
				</view>
				<view class="padding">单日总库存</view>
			</view>
		</view>
		<view class="cu-list grid col-3 no-border" >
			<view v-if="isShowTodo" class="cu-item" @tap="navTodo()">
				<view class="cuIcon-noticefill text-blue">
					<view class="cu-tag badge" v-if="badge!=0">
						<block>{{badge>99?'99+':badge}}</block>
					</view>
				</view>
				<text>待办</text>
			</view>
			<view v-if="isShowInPlan" class="cu-item" @tap="navToGoodsInPlan()">
				<view class="cuIcon-add text-blue">
				</view>
				<text>入库计划</text>
			</view>
			<view v-if="isShowOutPlan" class="cu-item" @tap="navToGoodsOutPlan()">
				<view class="cuIcon-move text-blue">
				</view>
				<text>出库计划</text>
			</view>
			<view v-if="isShowInBill" class="cu-item" @tap="navToGoodsInBill()">
				<view class="cuIcon-deliver_fill text-blue">
				</view>
				<text>入库</text>
			</view>
			<view v-if="isShowOutBill" class="cu-item" @tap="navToGoodsOutBill()">
				<view class="cuIcon-deliver text-blue">
				</view>
				<text>出库</text>
			</view>
			<view v-if="isShowQtyChk" class="cu-item" @tap="navToQtyChk()">
				<view class="cuIcon-post text-blue">
				</view>
				<text>盘点</text>
			</view>
			<view v-if="isShowInStockGoodsDetailChange" class="cu-item" @tap="navToInStockGoodsDetailChange()">
				<view class="cuIcon-write text-blue">
				</view>
				<text>库存货位调整</text>
			</view>
			<view v-if="isShowPosiChng" class="cu-item" @tap="navToGoodsPosiChngBill()">
				<view class="cuIcon-order text-blue">
				</view>
				<text>移库</text>
			</view>
			<view v-if="isShowAnalysis" class="cu-item" @tap="navToAnalysis()">
				<view class="cuIcon-rankfill text-blue">
				</view>
				<text>统计</text>
			</view>
			<view v-if="isShowInStockGoodsDetail" class="cu-item" @tap="navToInStockGoodsDetail()">
				<view class="cuIcon-formfill text-blue">
				</view>
				<text>库存查询</text>
			</view>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex'
	export default {
		computed: mapGetters(['loginType','user']),
		data() {
			return {
				goodsInBillYesterday: 0,
				goodsOutBillYesterday: 0,
				inStockGoodsDetailOnDayList: 0,
				badge: 0,
				cuIconList: [],
				
				isShowTodo: true,
				isShowInPlan: false,
				isShowOutPlan: false,
				isShowInBill: true,
				isShowOutBill: true,
				isShowPosiChng: false,
				isShowAnalysis: true,
				isShowInStockGoodsDetail: true,
				isShowQtyChk: true,
				isShowInStockGoodsDetailChange: true
				
			}
		},
		onLoad() {
			// if (this.loginType === '司机') {
			// 	this.isShowTodo = false
			// 	this.isShowInBill = false
			// 	this.isShowOutBill = false
			// 	this.isShowPosiChng = false
			// 	this.isShowAnalysis = false
			// }
			// else if (this.loginType === '客户') {
			// 	this.isShowTodo = false
			// 	this.isShowPosiChng = false
			// 	this.isShowAnalysis = false
			// }
		},
		onShow() {
			/*
			let params = {
			  }
			if (this.loginType === '客户') {
				params = {
				    clientID: this.user.clientId
				  }
			}
						
			this.$minApi.getGoodsInBillYesterday(params).then(res => {
				const data = res
				const weightValues = data.map(item => Number(item.weight))
				this.goodsInBillYesterday = weightValues.reduce((prev, curr) => { return prev + curr }, 0).toFixed(2)
			}).catch(err => {
				console.log(err)
			})
			this.$minApi.getGoodsOutBillYesterday(params).then(res => {
				const data = res
				const weightValues = data.map(item => Number(item.actualWeight))
				this.goodsOutBillYesterday = weightValues.reduce((prev, curr) => { return prev + curr }, 0).toFixed(2)
			}).catch(err => {
				console.log(err)
			})
			this.$minApi.getInStockGoodsDetailOnDayList(params).then(res => {
				const data = res
				const weightValues = data.map(item => Number(item.weight))
				this.inStockGoodsDetailOnDayList = weightValues.reduce((prev, curr) => { return prev + curr }, 0).toFixed(2)
			}).catch(err => {
				console.log(err)
			})
			
			this.badge = 0
			
			this.$minApi.getGoodsInOutChantToDo().then(res => {
				const data = res
				if (data) {
					const cnt = data.goodsInCnt+ data.goodsOutCnt+data.goodsPosiChngCnt+data.qtyChkCnt
					this.badge = cnt
				}
			}).catch(err => {
				console.log(err)
			})
			
			*/
		 //    //缓存货位
		 //    const data = uni.getStorageSync('storage_key_getGoodsWareHouses')
			// if(data){
				
			// }else{
			// 	this.$minApi.getGoodsWareHouses().then(res => {
			// 		const data = res
			// 		if (data) {
			// 			uni.setStorageSync('storage_key_getGoodsWareHouses', data)
			// 		}
			// 	}).catch(err => {
			// 		console.log(err)
			// 	}).finally(() => {
			// 	})
			// }
			
		},
		methods: {
			getGoodsPosiData(data) {
				
				var val = [];
				// 将数据存储为 以 id 为 KEY 的 map 索引数据列
				var map = {};
				data.forEach((item) => {
					map[item.id] = item
				})
				data.forEach((item) => {
					// 以当前遍历项，的pid,去map对象中找到索引的id
			
					var parent = map[item.fatherID]
					// 好绕啊，如果找到索引，那么说明此项不在顶级当中,那么需要把此项添加到，他对应的父级中
					if (parent) {
						(parent.children || ( parent.children = [] )).push(item)
					} else {
						//如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中，作为顶级
						val.push(item)
					}
				})
				
				return val
					
			},
			navTodo() {
				uni.redirectTo({
					url: '/pages/todo/index'
				})
			},
			navToGoodsInPlan() {
				uni.redirectTo({
					url: '/pages/goodsInPlan/list'
				})
			},
			navToGoodsOutPlan() {
				uni.redirectTo({
					url: '/pages/goodsOutPlan/list'
				})
			},
			navToGoodsInBill() {
				uni.redirectTo({
					url: '/pages/goodsInBill/list'
				})
			},
			navToGoodsOutBill() {
				uni.redirectTo({
					url: '/pages/goodsOutBill/list'
				})
			},
			navToGoodsPosiChngBill() {
				uni.redirectTo({
					url: '/pages/goodsPosiChngBill/list'
				})
			},
			navToAnalysis() {
				uni.redirectTo({
					url: '/pages/analysis/index'
				})
			},
			navToInStockGoodsDetail() {
				uni.redirectTo({
					url: '/pages/inStockGoodsDetail/index'
				})
			},
			navToQtyChk() {
				uni.redirectTo({
					url: '/pages/qtyChk/list'
				})
			},
			navToInStockGoodsDetailChange() {
				uni.redirectTo({
					url: '/pages/inStockGoodsDetailChange/list'
				})
			}
		}
	}
</script>
